package client.comm.baoding.ui

import android.content.Intent
import androidx.lifecycle.Observer
import client.comm.baoding.BaseMiddleActivity
import client.comm.baoding.R
import client.comm.baoding.api.bean.UserCards
import client.comm.baoding.databinding.ActivityBankmanagerDetailBinding
import client.comm.baoding.dialog.MsgTitleDialog
import client.comm.baoding.ui.vm.BankManagerViewModel
import client.comm.commlib.toast.toast

/**
 * Date: 2022/11/3 14:48
 * Description: 银行卡管理
 */
class BankDetailActivity : BaseMiddleActivity<BankManagerViewModel, ActivityBankmanagerDetailBinding>() {

    override fun getLayout(): Int {
        return R.layout.activity_bankmanager_detail
    }

    var bean: UserCards.Card? = null
    override fun initViewModel(): BankManagerViewModel = createViewModel()

    override fun initView() {
        super.initView()
        binding.apply {
            event = this@BankDetailActivity
        }
    }

    override fun initData() {
        super.initData()
        bean = intent.getParcelableExtra<UserCards.Card>("bean")
        binding.e = bean

        viewModel.delRet.observe(this, Observer {
            it?.let {
                if (it.isSuccess) {
                    toast("操作成功")
                    finish()
//                    holdCall()
                }
            }
        })

    }

    fun onUnbindBank() {
        MsgTitleDialog(this).apply {
            okTxt = "确定"
            cancleTxt = "关闭"
            title = "确定要解绑该银行卡吗？"
            ok = {
                viewModel.delCard(bean!!.link_id)
            }
        }.show()

    }

    fun onBankKt() {
        startActivity(Intent(this, BankkTxSimpleActivity::class.java).apply {
            putExtra("link_id", bean!!.link_id)
        })
        finish()
    }

}